// Decorator utility for transforming constant arrays into Map and Dict formats

/**
 * Creates a Map object where keys are the item.key and values are item.value
 * @param {Array} array - Array of objects with key and value properties
 * @returns {Object} - Object with keys mapped to values
 */
const createMap = (array) => array.reduce((acc, item) => {
    acc[item.key] = item.value;
    return acc;
}, {});

/**
 * Creates a Dict object where keys are the item.value and values are the full item
 * @param {Array} array - Array of objects with value property
 * @returns {Object} - Object with values mapped to full items
 */
const createDict = (array) => array.reduce((acc, item) => {
    acc[item.value] = item;
    return acc;
}, {});

/**
 * Decorator function that transforms a constant array into multiple formats
 * @param {Array} constantArray - The original constant array
 * @param {string} name - The name of the constant array
 * @returns {Object} - Object containing the original array, Map, and Dict versions
 */
export const withMapAndDict = (constantArray, name) => {
    return {
        [name]: constantArray,
        [`${name}_MAP`]: createMap(constantArray),
        [`${name}_DICT`]: createDict(constantArray)
    };
};